#ifndef __DriverSpilcd_H__
#define __DriverSpilcd_H__

#include <stdint.h>


// fm  pin  -> not use
// bl  pin  -> pa1
// res pin  -> pa2
// d/c pin  -> pa3
// cs  pin  -> pa4
// scl pin  -> pa5
// sdo pin  -> pa6
// sda pin  -> pa7

#define DIS_BACK_GPIO_Port  GPIOA
#define DIS_BACK_Pin        GPIO_PIN_0

#define DIS_RES_GPIO_Port   GPIOA
#define DIS_RES_Pin         GPIO_PIN_4

#define DIS_DC_GPIO_Port    GPIOB
#define DIS_DC_Pin          GPIO_PIN_0

#define LCD_CS_LOW()        SPI0_NSS_SET_LOW()
#define LCD_CS_HIGH()       SPI0_NSS_SET_HIGH()
#define LCD_BACK_LOW()      GPIO_BC(DIS_BACK_GPIO_Port)     = DIS_BACK_Pin
#define LCD_BACK_HIGH()     GPIO_BOP(DIS_BACK_GPIO_Port)    = DIS_BACK_Pin
#define LCD_RES_LOW()       GPIO_BC(DIS_RES_GPIO_Port)      = DIS_RES_Pin
#define LCD_RES_HIGH()      GPIO_BOP(DIS_RES_GPIO_Port)     = DIS_RES_Pin
#define LCD_DC_LOW()        GPIO_BC(DIS_DC_GPIO_Port)       = DIS_DC_Pin
#define LCD_DC_HIGH()       GPIO_BOP(DIS_DC_GPIO_Port)      = DIS_DC_Pin

#define ucLcdWriteByte      ucSPI0WriteReadByte
#define cLcdWriteDatas      cSPI0WriteDatas
#define cLcdDmaWriteDatas   cSPI0DmaWriteDatas
#define cLcdReadDatas       cSPI0ReadDatas


/* 定义液晶屏顺时针旋转方向 	0-0度旋转，1-90度旋转，2-180度旋转，3-270度旋转 */
#define USE_HORIZONTAL      3

/* 定义LCD的尺寸 */
#define LCD_W               240
#define LCD_H               320

/* 画笔颜色 */
#define WHITE               0xFFFF
#define BLACK               0x0000
#define BLUE                0x001F
#define BRED                0xF81F
#define GRED                0xFFE0
#define GBLUE               0x07FF
#define RED                 0xF800
#define MAGENTA             0xF81F
#define GREEN               0x07E0
#define CYAN                0x7FFF
#define YELLOW              0xFFE0


typedef struct
{
    uint32_t id;            /* LCD ID */
    uint16_t width;         /* LCD 宽度 */
    uint16_t height;        /* LCD 高度 */
    uint8_t direction;      /* 横屏还是竖屏控制：0，竖屏；1，横屏 */
} _lcd_dev;


void vLcdReset(void);
void vLcdDirection(uint8_t ucDirection);
void vLcdSetWindows(uint32_t xStar, uint32_t yStar, uint32_t xEnd, uint32_t yEnd);
void vLcdWriteDatas(void *pvDatas, int32_t iLength);
void vLcdClear(uint32_t xStar, uint32_t yStar, uint32_t xEnd, uint32_t yEnd, uint32_t uiColor);

int8_t cLcdStringShow(int32_t iXStart, int32_t iYStart, uint32_t uiColorFront, uint32_t uiColorBack, char *cStrings);

uint32_t uiLcdGetId(void);
void vLcdInit(void);
int8_t cLcdDesktopInit(void);
int8_t cLcdDesktopShow(void);

void vLcdSync(void);
int8_t cLcdRefresh(uint16_t usAddr, void *pvDatas, int32_t iSize);


#endif
